using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using MITI;

namespace MapControl.Misc.DAL
{
    public class Airport
    {
        public int Airport_Id;
        public string Airport_Name;
        public double Longitude;
        public double Latitude;
    }

    public static class AirPortRepository
    {
        public static DataTable GetAll()
        {
            string sql = "select * from airport";
            return BaseDBCe.ExecSql_DataSet(sql).Tables[0];
        }

        public static DataRow GetCurrentAirportDataRow()
        {
            string sql = "select * from airport where isActive = 1";
            DataRow dr = BaseDBCe.ExecSql_DataSet(sql).Tables[0].Rows[0];
            return dr;
        }

        public static Airport GetCurrentAirport()
        {
            DataRow dr = GetCurrentAirportDataRow();
            Airport objAirport = new Airport();
            objAirport.Airport_Id = int.Parse(dr["airport_id"].ToString());
            objAirport.Airport_Name = dr["airport_name"].ToString();
            objAirport.Longitude = double.Parse(dr["longitude"].ToString());
            objAirport.Latitude = double.Parse(dr["latitude"].ToString());
            return objAirport;
        }

        public static Airport GetAirportById(int airport_id)
        {
            string sql = "select * from airport where airport_id = " + airport_id;
            DataRow dr = BaseDBCe.ExecSql_DataSet(sql).Tables[0].Rows[0];
            Airport objAirport = new Airport();
            objAirport.Airport_Id = int.Parse(dr["airport_id"].ToString());
            objAirport.Airport_Name = dr["airport_name"].ToString();
            objAirport.Longitude = double.Parse(dr["longitude"].ToString());
            objAirport.Latitude = double.Parse(dr["latitude"].ToString());
            return objAirport;
        }

        public static void UpdateActiveAirport(int airport_id)
        {
            BaseDBCe.ExecSql_NoneQuery("update airport set isActive = 0");
            //int value = isActive ? 1 : 0;
            string sql = string.Format("update airport set isActive = 1 where airport_id = {0}", airport_id);
            BaseDBCe.ExecSql_NoneQuery(sql);
        }

        public static void UpdateAirportDistance(int airport_id, double distance)
        {
            string sql = string.Format("update airport set distance = {0} where airport_id = {1}", distance, airport_id);
            BaseDBCe.ExecSql_NoneQuery(sql);
        }

        
    }
}
